﻿#include <QApplication>
#include <QTextCodec>
#include <QWSServer>
#include <QFontDatabase>
#include <QElapsedTimer>
#include <QPixmap>
#include "MainWidget.h"
#include <QSplashScreen>
#include <QTranslator>
#include <signal.h>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>

void ShowStack (void)
{
    void *array[20];
    size_t size;
    char **strings;

    size = backtrace (array, 20);
    strings = backtrace_symbols (array, size);
    if (NULL == strings)
    {
        perror("backtrace_synbols");
        return;
    }

    printf ("Obtained %zd stack frames.\n", size);

    for (int i = 0; i < size; i++)
        printf ("%s\n", strings[i]);

    free (strings);

}

void sigsegv_handler(int signo)
{
    if (signo == SIGSEGV) {
        printf("Receive SIGSEGV signal\n");
        printf("-----call stack-----\n");
        ShowStack();
        exit(-1);
    }
}


int main(int argc, char *argv[])
{
    signal(SIGSEGV, sigsegv_handler);

    QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
    QTextCodec *codec = QTextCodec::codecForName("utf8");
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);

    QApplication a(argc, argv);
    QWSServer::setCursorVisible(false);//qws程序隐藏光标
/*设置字体*/
    QStringList fontList = QFontDatabase::applicationFontFamilies(QFontDatabase::addApplicationFont("/usr/lib/fonts/FZY3JW.TTF"));
    QFont font;
    if( fontList.size() > 0 )
    {
        font.setFamily(fontList.at(0));
    }
    QApplication::setFont(font);

//    QTranslator translator(0);
//    if(!translator.load("/usr/local/sanway/ch.qm"))
//    {
//        qDebug(">>>>>>>>>ch.qm<<<<<<<<<<<<<失败\n");
//    }
//    else
//    {
//        qDebug(">>>>>>>>>ch.qm<<<<<<<<<<<<<成功\n");
//    }
//    a.installTranslator(&translator);
//    QPixmap pixmapStart(":/Res/image/start.jpg");

    QPixmap pixmapStart;
    QDir dir("/usr/local/sanway/image");
    if(dir.exists())
    {
        pixmapStart.load("/usr/local/sanway/image/start.jpg");
    }
    else
    {
        pixmapStart.load(":/Res/image/start.jpg");

    }
    QSplashScreen  sScreen(pixmapStart);//QSplashScreen 启动画面的类型
    sScreen.show();

    QElapsedTimer timer;
    timer.start();

    while(timer.elapsed() < 3000)
    {

    }
    MainWidget w;
    w.show();
//    sScreen.finish(&w);
    
    return a.exec();
}
